<?php
if(!isset($_SESSION)){session_start();};

$uploaddir = 'stickers/'; 
$ext = substr($_FILES['uploadfile']['name'],strpos($_FILES['uploadfile']['name'],'.'));
$filename = $_FILES['uploadfile']['name']=time().$ext;
$file = $uploaddir . basename($filename); 

if(isset($_SESSION['img']) && unlink('stickers/'.$_SESSION['img'])){
	if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
		unset($_SESSION['img']);		
		$_SESSION['img'] = $filename;
		echo "success,".$filename; 
	} else {
		echo "error";
	}
}else{
	if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
		$_SESSION['img'] = $filename;
		echo "success,".$filename; 
	} else {
		echo "error";
	}
}

?>